// 云对象教程: https://uniapp.dcloud.net.cn/uniCloud/cloud-obj
// jsdoc语法提示教程：https://ask.dcloud.net.cn/docs/#//ask.dcloud.net.cn/article/129
module.exports = {
	_before: function () { // 通用预处理器

	},
	/**
	 * method1方法描述
	 * @param {string} param1 参数1描述
	 * @returns {object} 返回值描述
	 */
	async getPhoneNumber(code) {
	
		// 获取token
		const res = await uniCloud.httpclient.request('https://api.weixin.qq.com/cgi-bin/token', {
			method: 'get',
			data: {
				grant_type: 'client_credential',
				appid: 'wx43075af6660fe782',
				secret: '968073e75c30b67f806db8b6be95ff11'
			},
			dataType: 'json'
		
		})
		const token = res.data.access_token
		// 业务逻辑
		const phoneNumberRes = await uniCloud.httpclient.request('https://api.weixin.qq.com/wxa/business/getuserphonenumber?access_token=' + token, {
			method: 'POST',
			data: {
				code
			},
			dataType: 'json',
			contentType: 'json'

		})
		// 返回结果
		return {
			data: phoneNumberRes.data
		}
	}
}
